#include <iostream>
#include <taos.h>
#include <vector>

using namespace std;

int main() {
    taos_init();

    auto result = taos_connect("127.0.0.1", "root", "taosdata", "db", 0);
    cout << "client info: " << taos_get_client_info() << endl;
    cout << "server info: " << taos_get_server_info(result) << endl;

    auto table = taos_query(result,"select * from t");
    cout << "precision of the table: " << taos_result_precision(table) << endl;

    auto rows = taos_fetch_row(table);
    cout << "number of rows: " << taos_fetch_block(table, &rows) << endl;

    cout << "columns in the table: " << taos_num_fields(table) << endl;

    auto lens = taos_fetch_lengths(table);
    for(int i = 0;i<taos_num_fields(table);i++)
        cout << i << " rows: " << lens[i] << endl;

    cout << "affected rows: " << taos_affected_rows(table) << endl;

    auto types = taos_fetch_fields(table);
    for(int i = 0;i<taos_num_fields(table);i++)
        cout << i << " rows: " << " name: " << types[i].name << " type: " << (int)types[i].type << " bytes: " << types[i].bytes << endl;

    char** data = (char**)rows;
    for(int i = 0;i<taos_num_fields(table);i++)
        cout << i << " rows: " << data[i] << endl;

    taos_stop_query(table);
    taos_free_result(table);

    taos_close(result);
    taos_cleanup();

    return 0;
}